/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package au.edu.swin.bank.persistence.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Luke Horvat
 */
@Entity
@Table(name = "CUSTOMER")
@NamedQueries({
    @NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c"),
    @NamedQuery(name = "Customer.findByCustid", query = "SELECT c FROM Customer c WHERE c.custid = :custid"),
    @NamedQuery(name = "Customer.findByPassword", query = "SELECT c FROM Customer c WHERE c.password = :password"),
    @NamedQuery(name = "Customer.findByStaffmember", query = "SELECT c FROM Customer c WHERE c.staffmember = :staffmember")})
public class Customer implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "customer")
    private Collection<Bill> billCollection;
    @OneToMany(mappedBy = "customer")
    private Collection<Account> accountCollection;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Basic(optional = false)
    @Column(name = "CUSTID")
    private Integer custid;
    @Column(name = "PASSWORD")
    private Integer password;
    @Column(name = "STAFFMEMBER")
    private Integer staffmember;

    public Customer() {
    }

    public Customer(Integer custid) {
        this.custid = custid;
    }

    public Integer getCustId() {
        return custid;
    }

    public void setCustId(Integer custid) {
        this.custid = custid;
    }

    public Integer getPassword() {
        return password;
    }

    public void setPassword(Integer password) {
        this.password = password;
    }

    public Integer getStaffmember() {
        return staffmember;
    }

    public void setStaffmember(Integer staffmember) {
        this.staffmember = staffmember;
    }

    public Collection<Bill> getBillCollection() {
        return billCollection;
    }

    public void setBillCollection(Collection<Bill> billCollection) {
        this.billCollection = billCollection;
    }

    public Collection<Account> getAccountCollection() {
        Collection<Account> accountList = new ArrayList<Account>();
        Iterator iter = accountCollection.iterator();
        Account a;
        while (iter.hasNext()) {
            a = (Account)iter.next();
            if (a.getRemoved() == 0)
                accountList.add(a);
        }

        return accountList;
    }

    public void setAccountCollection(Collection<Account> accountCollection) {
        this.accountCollection = accountCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (custid != null ? custid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.custid == null && other.custid != null) || (this.custid != null && !this.custid.equals(other.custid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "au.edu.swin.bank.persistence.entity.Customer[custid=" + custid + "]";
    }
}
